package com.feicheng.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feicheng.common.exception.SystemException;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Adv;
import com.feicheng.persistence.entity.Sample;
import com.feicheng.service.IFAdvService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangxianchen
 * @since 2022-02-23
 */
@RestController
@RequestMapping("/admin/adv")
public class AdvController {
	
	@Autowired
	IFAdvService advService;
	
	//广告详情查询接口
	@GetMapping("/info") public ResultInfo getAdvInfo (Integer advId) {
	 if(null == advId) { throw new SystemException("案例主键缺失"); }
	 
	 return advService.getAdvInfo(advId); }
	 
	//用于分页查询广告接口
	@GetMapping("/page")
	public ResultInfo getAdvByPage( 
			Adv adv,
			@RequestParam(defaultValue="1") Integer current, 
			@RequestParam(defaultValue="10")Integer size) {
		return advService.getAdvByPage(adv,current,size);
	}
	
	//用于修改广告页面接口
	@PutMapping("/info")
	public ResultInfo updateAdv(Adv adv,String url,Boolean imgStatu,Boolean Dflg) {
		if (adv.getAdvId() == null) {
			throw new SystemException("丢失主键");
		}
		return ResultInfo.success(advService.updateAdv(adv,url,imgStatu,Dflg));
	}
	
	//用于新增广告页面接口
	@PostMapping("/new")
	public ResultInfo insertAdv(Adv adv,String url,Boolean imgStatu,Boolean Dflg) {
		if (url == null) {
			throw new SystemException("图片丢失");
		}
		return advService.insertAdv(adv,url,imgStatu,Dflg);
	}
	
	//用于删除广告页面接口
	@DeleteMapping("/info")
	public ResultInfo deleteAdvInfo(Integer advId) {
		
		if(null == advId){
            throw new SystemException("广告ID缺失");
        }
		
		return advService.deleteAdvInfo(advId);
	}
	
	
}
